Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2Platformconf = require("Platformconf");
var def_InteractiveMgr = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
  }
  return babel_createClass(_ctor, null, [{
    key: "modifyInteractiveStorage",
    value: function modifyInteractiveStorage(e, t) {
      if ($2Platformconf.default.PlatformType == $2Platformconf.ePlatformType.WXGame && wx && wx.eqapi) {
        console.log("修改玩家托管数据", e);
        wx.eqapi.sendevent("modifyInteractiveStorage", this.code(e), t);
      }
    }
  }, {
    key: "getInteractiveStorage",
    value: function getInteractiveStorage(e) {
      var _this45 = this;
      return new Promise(function (t) {
        $2Platformconf.default.PlatformType == $2Platformconf.ePlatformType.WXGame && wx && wx.eqapi && "" != e && wx.eqapi.sendevent("getInteractiveStorage", _this45.code({
          key: e
        }), function (n) {
          var o = _this45.decode(n.data, e);
          console.log("获取到的托管数据:", o);
          t(o);
        });
      });
    }
  }, {
    key: "addBeInvitedRecords",
    value: function addBeInvitedRecords(e, t, n) {
      var _this46 = this;
      this.getInteractiveStorage(e).then(function (o) {
        if (o.data && null != o.data.beInvitedRecords) {
          var _i9 = o.data.beInvitedRecords.find(function (e) {
            return e.interactivekey === t;
          });
          console.log(e, "被", t, "邀请了", _i9);
          if (!_i9) {
            o.data.beInvitedRecords.push({
              interactivekey: t,
              time: n
            });
            _this46.modifyInteractiveStorage(o, function (e) {
              console.log("修改结果：", e, _this46.decode(e, ""));
            });
          }
        }
      });
    }
  }, {
    key: "addInvitedRecords",
    value: function addInvitedRecords(e, t, n, o) {
      var _this47 = this;
      this.getInteractiveStorage(t).then(function (_i10) {
        if (_i10.data && null != _i10.data.beInvitedRecords) {
          var s = _i10.data.beInvitedRecords.find(function (t) {
            return t.interactivekey === e;
          });
          console.log("我的邀请列表有这个人吗？", s);
          !s && 0 != _i10.data.beInvitedRecords.length && o || _this47.getInteractiveStorage(e).then(function (o) {
            if (o.data && null != o.data.inviteRecords) {
              var _i11 = o.data.inviteRecords.find(function (e) {
                return e.interactivekey === t;
              });
              console.log(e, "邀请了", t, _i11);
              if (!_i11) {
                o.data.inviteRecords.push({
                  interactivekey: t,
                  time: n
                });
                _this47.modifyInteractiveStorage(o);
              }
            }
          });
          var a = _i10.data.beInvitedRecords.find(function (t) {
            return t.interactivekey === e;
          });
          console.log(t, "被", e, "邀请了", a);
          if (!a) {
            _i10.data.beInvitedRecords.push({
              interactivekey: e,
              time: n
            });
            _this47.modifyInteractiveStorage(_i10);
          }
        }
      });
    }
  }, {
    key: "decode",
    value: function decode(e, t) {
      var n = null;
      if (null == e) {
        n = {
          key: t,
          data: {
            beInvitedRecords: [],
            inviteRecords: []
          }
        };
      } else {
        e = this.atob(e);
        var _t22 = "";
        for (var _n20 = 0; _n20 < e.length; _n20++) {
          _t22 += String.fromCharCode(e.charCodeAt(_n20) + 32);
        }
        _t22 = this.atob(_t22);
        n = JSON.parse(_t22);
      }
      return n;
    }
  }, {
    key: "code",
    value: function code(e) {
      var t = this.btoa(JSON.stringify(e));
      var n = "";
      for (var _o50 = 0; _o50 < t.length; _o50++) {
        n += String.fromCharCode(t.charCodeAt(_o50) - 32);
      }
      return this.btoa(n);
    }
  }, {
    key: "btoa",
    value: function btoa(e) {
      var t;
      var n = String(e);
      var o = 0;
      var _i12 = this.chars;
      for (var s = ""; n.charAt(0 | o) || (_i12 = "=", o % 1); s += _i12.charAt(63 & t >> 8 - o % 1 * 8)) {
        t = t << 8 | n.charCodeAt(o += .75);
      }
      return s;
    }
  }, {
    key: "atob",
    value: function atob(e) {
      var t = String(e).replace(/[=]+$/, "");
      t.length;
      var n;
      var o;
      var _i13 = 0;
      var s = 0;
      for (var a = ""; o = t.charAt(s++); ~o && (n = _i13 % 4 ? 64 * n + o : o, _i13++ % 4) ? a += String.fromCharCode(255 & n >> (-2 * _i13 & 6)) : 0) {
        o = this.chars.indexOf(o);
      }
      return a;
    }
  }]);
}();
exports.default = def_InteractiveMgr;
def_InteractiveMgr.chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";